import 'package:flutter/material.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/provide/radio_state_provider.dart';
import 'package:full_display/unit/asset_utils/asset_utils.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:provider/provider.dart';

class RadioWidget extends StatelessWidget {
  List list = [];
  bool isBg;
  bool isRow;
  RadioWidget(
      {required this.list, required this.isBg, required this.isRow, Key? key})
      : super(key: key);

  late RadioStateProvider _radioData;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: bodyWidget(list, context),
    );
  }

  Widget bodyWidget(List list, BuildContext context) {
    return isRow
        ? Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: List<Widget>.generate(list.length,
                (index) => radioWidgetlist(list[index], index, list, context)),
          )
        : Column(
            children: List<Widget>.generate(list.length,
                (index) => radioWidgetlist(list[index], index, list, context)),
          );
  }

  Widget radioWidgetlist(item, index, list, BuildContext context) {
    _radioData = context.watch<RadioStateProvider>();
    return GestureDetector(
      onTap: () {
        for (var radio in list) {
          radio["isSelect"] = false;
        }
        list[index]["isSelect"] = true;
        _radioData.listIndex = index;
        _radioData.notifyListeners();
      },
      child: Container(
        padding: EdgeInsets.only(top: 20.0.W),
        child: Row(
          children: [
            Container(
              width: 20.0.W,
              height: 20.0.W,
              child: item["isSelect"]
                  ? Image.asset(
                      height: 30.0.H,
                      width: 30.0.W,
                      AssetUtils.getAsset2Image(
                          isBg ? "icon_item_select" : "icon_select"),
                    )
                  : Image.asset(
                      height: 30.0.H,
                      width: 30.0.W,
                      AssetUtils.getAsset2Image("icon_noselect"),
                    ),
            ),
            const SizedBox(
              width: 10,
            ),
            Text(
              item["title"],
              style: StandardTextStyle.textWhite14Style,
            ),
          ],
        ),
      ),
    );
  }
}
